﻿using System.Linq;
using MDK.Device.Components;

namespace MDK.Device.Devices
{
    public class Atm
    {
        public Atm(IPlcDevice device)
        {
            Device = device;
            InitializeComponents();
        }

        public IPlcDevice Device { get; }

        public IActuator Door { get; private set; }
        public ISensor DoorAntiPinch { get; private set; }
        public IActuator Belt { get; private set; }
        public ISensor BeltStartSensor { get; private set; }
        public ISensor BeltCorrelation { get; private set; }
        public ISensor BeltEndSensor { get; private set; }
        public IActuator CarmeraDamBoard { get; private set; }
        public ISensor CarmeraDamBoardSensor { get; private set; }
        public ISensor CarmeraDamBoardSafeSensor { get; private set; }
        public IActuator CrossingDamBoard { get; private set; }
        public ISensor CrossingDamBoardSafeSensor { get; private set; }
        public IActuator CrossingPushrod { get; private set; }
        public ISensor CrossingPushrodSensor { get; private set; }
        public ISensor CrossingPushrodSafeSensor { get; private set; }
        public ISwitch AtmCamerePower { get; private set; }
        public ISwitch CarmeraPower { get; private set; }
        public IScanner FreezerBeltScanner { get; private set; }
        public ICamera BeltCamera { get; private set; }
        public ISwitch Lamp { get; private set; }

        private void InitializeComponents()
        {
            Door = new DelayActuator(Device, "M280", "M281", "M282", Constants.DelayFor3);
            DoorAntiPinch = new Sensor(Device, "X70", false);
            Belt = new DelayActuator(Device, "M296", "M297", "M298");
            BeltStartSensor = new Sensor(Device, "X71");
            BeltEndSensor = new Sensor(Device, "X75");
            BeltCorrelation = new Sensor(Device, "X80");
            CarmeraDamBoard = new DelayActuator(Device, "M284", "M285", "M286", Constants.DelayFor2);
            CrossingDamBoard = new DelayActuator(Device, "M288", "M289", "M290", Constants.DelayFor2);
            CrossingPushrod = new DelayActuator(Device, "M292", "M293", "M294", Constants.DelayFor1);
            CrossingPushrodSensor = new Sensor(Device, "X73");
            AtmCamerePower = new Switch(Device, "M22");
            CarmeraPower = new Switch(Device, "M23");
            CarmeraDamBoardSensor = new Sensor(Device, "X75");
            CarmeraDamBoardSafeSensor = new Sensor(Device, "X76");
            CrossingDamBoardSafeSensor = new Sensor(Device, "X72");
            CrossingPushrodSafeSensor = new Sensor(Device, "X76");
            BeltCamera = new StdCamera(StdCamera.GetAllCamera().FirstOrDefault(t => t.Name.Contains("hRQ")));
            Lamp = new Switch(Device, "M22");
        }
    }
}